package com.zfzs.post.exception;

import com.zfzs.post.common.bean.ResponseCode;
import lombok.Getter;

import static org.springframework.http.HttpStatus.BAD_REQUEST;

/**
 * @author ck
 * @date 2018-11-23
 * 统一异常处理
 */
@Getter
public class BadRequestException extends RuntimeException{

    private String code;
    private String msg;
    private Exception e;

    private Integer status = BAD_REQUEST.value();

    public BadRequestException(String msg){
        this.code = ResponseCode.FAIL.code;
        this.msg = msg;
    }

    public BadRequestException(String code,String msg){
        super(msg);
        this.code = code;
    }

    public BadRequestException(ResponseCode statusEnum, Exception e){
        this.code = statusEnum.code;
        this.msg = statusEnum.msg;
        this.e = e;
    }

    public BadRequestException(ResponseCode statusEnum){
        this.code = statusEnum.code;
        this.msg = statusEnum.msg;
    }

    public BadRequestException(ResponseCode statusEnum,String msg){
        this.code = statusEnum.code;
        this.msg = msg;
    }
}
